package com.webmall.servlet.cart;

import com.webmall.entity.CartEntity;
import com.webmall.entity.CateEntity;
import com.webmall.entity.ProdEntity;
import com.webmall.entity.UserEntity;
import com.webmall.service.webmall_CartDao;
import com.webmall.service.webmall_ProdDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/ShowCart")
public class ShowCart extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        String isLogin = String.valueOf(session.getAttribute("isLogin"));


        if (!isLogin.equals("1")){
            PrintWriter out = response.getWriter();
            out.write("<script>");
            out.write("alert('请先登录！');");
            out.write("location.href='login.jsp';");
            out.write("</script>");
            out.close();
        }else {
            UserEntity user = (UserEntity) session.getAttribute("login_user");

            ArrayList<CartEntity>  cartList = webmall_CartDao.selectByUId(user.getUSER_ID());
  //          System.out.println(cartList.size());
            request.setAttribute("cartList",cartList);
            request.getRequestDispatcher("cart.jsp").forward(request,response);
//
//            int pid = cartList.get(0).getCART_PID();
//            ArrayList<ProdEntity> prodList = webmall_ProdDao.selectByCATEId(2,String.valueOf(pid));
//
//            request.setAttribute("cartList",cartList);
//            request.setAttribute("prodList",prodList);
//            request.getRequestDispatcher("cart.jsp").forward(request,response);
//



        }


    }
}
